﻿
using ServiceStack.Redis;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ServiceStack.Redis.Pipeline;
namespace RedisAnotherDemo
{
    public class RedisConnectSettings
    {
        public string url { get; set; }
        public string port { get; set; }
    }

    class Program
    {
        //.NET客户端实现Redis中的管道（PipeLine）与事物（Transactions） http://www.cnblogs.com/knowledgesea/p/6552799.html
        static void Main(string[] args)
        {
            Stopwatch watch = new Stopwatch();
            Stopwatch watch1 = new Stopwatch();
            watch.Start();
            GetNoPipelining();
            Console.WriteLine("一般循环耗时：" + watch.ElapsedMilliseconds);
            watch.Stop();
            watch1.Start();
            GetPipelining();
            Console.WriteLine("Pipelining插入耗时：" + watch1.ElapsedMilliseconds);
            watch1.Stop();
            Console.ReadLine();
        }
        //redis  一次读取多个值  
//        On the ServiceStack.Redis client you can use GetValues or GetValuesMap(both string and T apis are available) for fetching multiple values(uses MGET) in a single call
//            .Only existing items are returned, which you can detect with GetValues if you have Id's on your models or GetValuesMap which returns a dictionary of existing keys and their values.
//From this, you can determine and fetch all the missing Ids from the database. If you're just going to fetch the existing values from Redis anyway, then this is the most optimal strategy since you 
//    can fetch all the values and determine the existing keys with 1 call.
       static RedisClient client = new RedisClient("");
            
        public static void GetNoPipelining()
       {

        }
        public static void GetPipelining()
        {
            //var batch = db.CreateBatch();
            //for (int i = 0; i < 5000; i++)
            //{
            //    var key = "mename:" + i;
            //    batch.StringAppendAsync(key, "张龙豪");
            //}
            //batch.Execute();
           
        }

        public static void CreatePipelining()
        {
            IRedisPipeline pipeline=   client.CreatePipeline();
      
            var comand= client.CreatePipelineCommand();
           
        }
        

       
    }

  
}
